home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 10 / database / vtest.c < prev   
Text File  |  1987-10-13  |  3KB  |  103 lines

  1. /*                     VTEST.C test program.                        */
  2. /*  This is a simple test program which creates two index files.    */
  3. /*  100 keys are added to each file, some keys are deleted and      */
  4. /*  then the keys are added back to the file.  The keys are listed  */
  5. /*  in ascending and decending order.                               */
  6.  
  7. #include "bplus.h"
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <conio.h>
  11.  
  12. IX_DESC name1, name2;        /* index file variables */
  13.  
  14. void uplist(name)            /* list keys in ascending order */
  15.   IX_DESC *name;
  16.   {
  17.     ENTRY ee;
  18.     first_key(name);
  19.     while (next_key(&ee, name) == IX_OK) printf("%s   ",ee.key);
  20.     printf("\nPress any key to continue \n");
  21.     getch();
  22.   }
  23.  
  24. void downlist(name)           /* list keys in decending order  */
  25.   IX_DESC *name;
  26.   {
  27.     ENTRY ee;
  28.     last_key(name);
  29.     while (prev_key(&ee, name) == IX_OK) printf("%s   ",ee.key);
  30.     printf("\nPress any key to continue \n");
  31.     getch();
  32.   }
  33.  
  34. main()
  35.   {
  36.     long i;
  37.     long ltime;
  38.     ENTRY e;
  39.     printf("Make two index files\n");
  40.     make_index("test1.idx",&name1, 0);
  41.     make_index("test2.idx",&name2, 1);
  42.     printf("Indexing 100 items in two index files:\n");
  43.  
  44.     /* note the time to index */
  45.     time(<ime);
  46.     printf("%s",ctime(<ime));
  47.  
  48.     /* add 100 keys to each index file */
  49.     for (i = 0L; i < 100L; i++)
  50.       {
  51.         e.recptr = i;
  52.         sprintf(e.key, "VALUE1-%2d",i);
  53.         add_key(&e, &name1);
  54.         sprintf(e.key, "VALUE2-%2d",i);
  55.         add_key(&e, &name2);
  56.       }
  57.  
  58.     /* print the time required for indexing the two files */
  59.     time(<ime);
  60.     printf("%s",ctime(<ime));
  61.     printf("Indexing is complete\n\n");
  62.     printf("List the keys in each index file in ascending order:\n\n");
  63.     uplist(&name1);
  64.     uplist(&name2);
  65.  
  66.     /* delete some keys and list again */
  67.     printf("\nNow delete all keys from 20 to 90 in each file\n\n");
  68.     for (i = 20L; i < 90L; i++)
  69.       {
  70.         e.recptr = i;
  71.         sprintf(e.key, "VALUE1-%2d",i);
  72.         delete_key(&e, &name1);
  73.         sprintf(e.key, "VALUE2-%2d",i);
  74.         delete_key(&e, &name2);
  75.       }
  76.     printf("List the keys now for each index file in ascending order:\n\n");
  77.     uplist(&name1);
  78.     uplist(&name2);
  79.  
  80.     /* add the keys back and list again */
  81.     printf("Now add back all items from 20 to 90 to each index\n\n");
  82.     for (i = 20L; i < 90L; i++)
  83.       {
  84.         e.recptr = i;
  85.         sprintf(e.key, "VALUE1-%d",i);
  86.         add_key(&e, &name1);
  87.         sprintf(e.key, "VALUE2-%d",i);
  88.         add_key(&e, &name2);
  89.       }
  90.     printf("List the keys for each index file again in ascending order:\n\n");
  91.     uplist(&name1);
  92.     uplist(&name2);
  93.  
  94.     /* list both files in decending order */
  95.     printf("List the keys for each index file in decending order\n\n");
  96.     downlist(&name1);
  97.     downlist(&name2);
  98.  
  99.     /* always close all files */
  100.     close_index(&name1);
  101.     close_index(&name2);
  102.   }
  103.